/*************************************************************************
> File Name: 04_class_object.cpp
> Author: hzy
> Created Time: 2023-08-10 10:39:19
> Description: 类对象作为成员变量
************************************************************************/
#include <iostream>

using namespace std;

class A
{
public:
    A()
    {
        // val = myval;
        cout << "A:" << endl;
    }

    ~A()
    {
        cout << "~A:" << endl;
    }

public:
    int val;
};

class B
{
public:
    B() 
    {
        cout << "B:" << endl;
    }

    ~B()
    {
        cout << "~B:" << endl;
    }

public:
    int num;
};

class Demo : public B
{
public:
    Demo(int myval, int mynum) : b_obj(),a_obj()
    {
        cout << " Demo(int myval, int mynum):" << endl;
    }
    ~Demo()
    {
        cout << " ~Demo():" << endl;
    }

public:
    A a_obj;
    B b_obj;
};

int main()
{
    Demo obj(1, 5);     //自动调用构造函数的顺序：A的构造，B的构造，Demo的构造

    // cout << obj.a_obj.val << endl;
    // cout << obj.b_obj.num << endl;

    //模块结束的时候：调用析构函数的顺序：Demo的析构，B的析构，A的析构

    return 0;
}